home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / gfx / show / GS510_data.lha / ghostscript / 5.10 / gs_fonts.ps < prev    next >
Text File  |  1997-12-28  |  28KB  |  913 lines

  1. %    Copyright (C) 1990, 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % Font initialization and management code.
  16.  
  17. % Define the default font.
  18. /defaultfontname /Courier def
  19.  
  20. % Define the name of the font map file.
  21. /defaultfontmap (Fontmap) def
  22.  
  23. % ------ End of editable parameters ------ %
  24.  
  25. % If SUBSTFONT is defined, make it the default font.
  26. /SUBSTFONT where { pop /defaultfontname /SUBSTFONT load def } if
  27.  
  28. % Define a reliable way of accessing FontDirectory in systemdict.
  29. /.FontDirectory
  30. { //systemdict /FontDirectory get
  31. } bind odef
  32.  
  33. % If DISKFONTS is true, we load individual CharStrings as they are needed.
  34. % (This is intended primarily for machines with very small memories.)
  35. % In this case, we define another dictionary, parallel to FontDirectory,
  36. % that retains an open file for every font loaded.
  37. /FontFileDirectory 10 dict def
  38.  
  39. % Define a temporary string for local use, since using =string
  40. % interferes with some PostScript programs.
  41. /.fonttempstring 128 string def
  42.  
  43. % Split up a search path into individual directories or files.
  44. /.pathlist        % <path> .pathlist <dir1|file1> ...
  45.  {  { dup length 0 eq { pop exit } if
  46.       .filenamelistseparator search not { exit } if
  47.       exch pop exch
  48.     }
  49.    loop
  50.  } bind def
  51.  
  52. % Load a font name -> font file name map.
  53. userdict /Fontmap .FontDirectory maxlength dict put
  54. /.loadFontmap        % <file> .loadFontmap -
  55.  {        % We would like to simply execute .definefontmap as we read,
  56.         % but we have to maintain backward compatibility with an older
  57.         % specification that makes later entries override earlier.
  58.    50 dict exch
  59.     { dup token not { closefile exit } if
  60.         % stack: <file> fontname
  61.       % This is a hack to get around the absurd habit of MS-DOS editors
  62.       % of adding an EOF character at the end of the file.
  63.       dup (\032) eq { pop closefile exit } if
  64.       1 index token not
  65.        { (Fontmap entry for ) print dup =only
  66.      ( has no associated file or alias name!  Giving up.\n) print flush
  67.      {.loadFontmap} 0 get 1 .quit
  68.        } if
  69.       dup type dup /stringtype eq exch /nametype eq or not
  70.        { (Fontmap entry for ) print 1 index =only
  71.      ( has an invalid file or alias name!  Giving up.\n) print flush
  72.      {.loadFontmap} 0 get 1 .quit
  73.        } if
  74.         % stack: dict file fontname filename|aliasname
  75.         % Read and pop tokens until a semicolon.
  76.        { 2 index token not
  77.       { (Fontmap entry for ) print 1 index =only
  78.         ( ends prematurely!  Giving up.\n) print flush
  79.         {.loadFontmap} 0 get 1 .quit
  80.       } if
  81.      dup /; eq { pop 3 index 3 1 roll .growput exit } if
  82.      pop
  83.        } loop
  84.     } loop
  85.     { .definefontmap } forall
  86.  } bind def
  87. % Add an entry in Fontmap.  We redefine this if the Level 2
  88. % resource machinery is loaded.
  89. /.definefontmap            % <fontname> <file|alias> .definefontmap -
  90.  {        % Since Fontmap is global, make sure the values are storable.
  91.    .currentglobal 3 1 roll true .setglobal
  92.    dup type /stringtype eq
  93.     { dup .gcheck not { dup length string copy } if
  94.     }
  95.    if
  96.    Fontmap 3 -1 roll 2 copy .knownget
  97.     {        % Add an element to the end of the existing value,
  98.         % unless it's the same as the current last element.
  99.       mark exch aload pop counttomark 4 add -1 roll
  100.       2 copy eq { cleartomark pop pop } { ] readonly .growput } ifelse
  101.     }
  102.     {        % Make a new entry.
  103.       mark 4 -1 roll ] readonly .growput
  104.     }
  105.    ifelse .setglobal
  106.  } bind def
  107.  
  108. % Parse a font file just enough to find the FontName or FontType.
  109. /.findfontvalue        % <file> <key> .findfontvalue <value> true
  110.             % <file> <key> .findfontvalue false
  111.             % Closes the file in either case.
  112.  { exch dup read not { -1 } if
  113.    2 copy unread 16#80 eq
  114.     { dup (xxxxxx) readstring pop pop }        % skip .PFB header
  115.    if
  116.         % Stack: key file
  117.     { dup token not { false exit } if        % end of file
  118.       dup /eexec eq { pop false exit } if    % reached eexec section
  119.       dup /Subrs eq { pop false exit } if    % Subrs without eexec
  120.       dup /CharStrings eq { pop false exit } if    % CharStrings without eexec
  121.       dup 3 index eq
  122.        { xcheck not { dup token exit } if }    % found key
  123.        { pop }
  124.       ifelse
  125.     } loop
  126.         % Stack: key file value true   (or)
  127.         % Stack: key file false
  128.    dup { 4 } { 3 } ifelse -2 roll closefile pop
  129.  } bind def
  130. /.findfontname
  131.  { /FontName .findfontvalue
  132.  } bind def
  133.  
  134. % If there is no FONTPATH, try to get one from the environment.
  135. NOFONTPATH { /FONTPATH () def } if
  136. /FONTPATH where
  137.  { pop }
  138.  { /FONTPATH (GS_FONTPATH) getenv not { () } if def }
  139. ifelse
  140. FONTPATH length 0 eq { (%END FONTPATH) .skipeof } if
  141. /FONTPATH [ FONTPATH .pathlist ] def
  142.  
  143. % Scan directories looking for plausible fonts.  "Plausible" means that
  144. % the file begins with %!PS-AdobeFont or %!FontType1, or with \200\001
  145. % followed by four arbitrary bytes and then either of these strings.
  146. % To speed up the search, we skip any file whose name appears in
  147. % the Fontmap (with any extension and upper/lower case variation) already,
  148. % and any file whose extension definitely indicates it is not a font.
  149. %
  150. % NOTE: The current implementation of this procedure is somewhat Unix/DOS-
  151. % specific.  It assumes that '/' and '\' are directory separators, and that
  152. % the part of a file name following the last '.' is the extension.
  153. %
  154. /.lowerstring        % <string> .lowerstring <lowerstring>
  155.  { 0 1 2 index length 1 sub
  156.     { 2 copy get dup 65 ge exch 90 le and
  157.        { 2 copy 2 copy get 32 add put }
  158.      if pop
  159.     }
  160.    for
  161.  } bind def
  162. /.splitfilename        % <dir.../base.extn> .basename <base> <extn>
  163.  {  { (/) search { true } { (\\) search } ifelse
  164.        { pop pop }
  165.        { exit }
  166.       ifelse
  167.     }
  168.    loop
  169.    dup { (.) search { pop pop } { exit } ifelse } loop
  170.    2 copy eq
  171.     { pop () }
  172.     { exch dup length 2 index length 1 add sub 0 exch getinterval exch }
  173.    ifelse
  174. % Following is debugging code.
  175. %   (*** Split => ) print 2 copy exch ==only ( ) print ==only
  176. %   ( ***\n) print flush
  177.  } bind def
  178. /.scanfontdict 1 dict def        % establish a binding
  179. /.scanfontbegin
  180.  {    % Construct the table of all file names already in Fontmap.
  181.    currentglobal true setglobal
  182.    .scanfontdict dup maxlength Fontmap length 2 add .max .setmaxlength
  183.    Fontmap
  184.     { exch pop
  185.        { dup type /stringtype eq
  186.       { .splitfilename pop .fonttempstring copy .lowerstring cvn
  187.         .scanfontdict exch true put
  188.       }
  189.       { pop
  190.       }
  191.      ifelse
  192.        }
  193.       forall
  194.     }
  195.    forall
  196.    setglobal
  197.  } bind def
  198. /.scanfontskip mark
  199.         % Strings are converted to names anyway, so....
  200.   /afm true
  201.   /bat true
  202.   /c true
  203.   /cmd true
  204.   /com true
  205.   /dll true
  206.   /doc true
  207.   /drv true
  208.   /exe true
  209.   /fon true
  210.   /fot true
  211.   /h true
  212.   /o true
  213.   /obj true
  214.   /pfm true
  215.   /pss true        % Adobe Multiple Master font instances
  216.   /txt true
  217. .dicttomark def
  218. /.scan1fontstring 128 string def
  219. /.scanfontheaders [(%!PS-Adobe*) (%!FontType*)] def
  220. 0 .scanfontheaders { length max } forall 6 add    % extra for PFB header
  221. /.scan1fontfirst exch string def
  222. /.scanfontdir        % <dirname> .scanfontdir -
  223.  { currentglobal exch true setglobal
  224.    QUIET not { (Scanning ) print dup print ( for fonts...) print flush } if
  225.    (*) 2 copy .filenamedirseparator
  226.    dup (\\) eq { pop (\\\\) } if    % double \ for pattern match
  227.    exch concatstrings concatstrings
  228.    0 0 0 4 -1 roll    % found scanned files
  229.     {        % stack: <fontcount> <scancount> <filecount> <filename>
  230.       exch 1 add exch                   % increment filecount
  231.       dup .splitfilename .lowerstring
  232.         % stack: <fontcount> <scancount> <filecount+1> <filename>
  233.         %    <BASE>